package cli.menu;

/**
 * BudgetBuoy
 * 
 * Simplify your personal expense management
 * 
 * @team cs2103jan13-w15-3j
 */

//--------------------------------------------------------------

/**
 * AddCategory Class
 * 
 * Description: 
 * 
 * 
 * @package   cli.menu
 * @author    Lai Yong Quan (A0080909Y)
 * @edited by: Tan Si Ling (A0085314J)
 */

import shared.Category;
import cli.tools.Process;


class AddCategory extends Function{

	private static final String[] ADDCAT = {
		"-= Main menu > Manage Categories =-",
		"",
		"Enter the name for the new category: "
	};

	private static final String[] FAIL = {
		"Failed to add category"
	};

	private static State BACK = State.MANAGECATEGORIES;
	private static State CURRENT = State.ADDCATEGORY;

	public static State runMenu(){
		
		String input = null;
		while(input == null || input.length() == 0){
		cli.print(ADDCAT);
		input = cli.nextLine();
		cli.clearScreen();
		}
		
		Category category;
		try{
			category = cli.getApi().addCategory(input);
		}
		catch(Exception e){	
			cli.print(FAIL);
			return CURRENT;
		}
		// Si Ling: **Keeping Track of the Actions DONE**
		tools.action.addToUndoStack((Object) null, category, Process.ADDCATEGORIES,
				(Object) null);
		// **END**
		return BACK;

	}


}

